package com.acme;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class AwardWinner {

	public static final String AWARD_NAME = "award_name";

	public String year;
	public String firstName;
	public String lastName;
	public String id;
	
	public static ArrayList<AwardWinner> getAwardWinners(String winnersJSON){
		try {
			return getAwardWinners(new JSONArray(winnersJSON));
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static ArrayList<AwardWinner> getAwardWinners(JSONArray winners){
		
		ArrayList<AwardWinner> winnerList = new ArrayList<AwardWinner>();
		
		try {
			
			int length = winners.length();
			
			for (int i = 0; i < length; i++){
				
				JSONObject winnerJSON = winners.getJSONObject(i);
				
				AwardWinner winner = new AwardWinner();
				winner.firstName = winnerJSON.getString("first_name");
				winner.lastName = winnerJSON.getString("last_name");
				winner.year = winnerJSON.getString("year");
				winner.id = winnerJSON.getString("id");
				
				winnerList.add(winner);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return winnerList;
	}
	
	public String toString(){
		return firstName+" "+lastName+":"+year+":"+id;
	}
}
